<?php
class ServiceManager extends Model{
	
	public function getListeMenu($id_professionnel){
		$req = $this->pdo->prepare('SELECT * FROM menu_restaurant WHERE id_professionnel = :id');
		$req->bindValue(':id',$id_professionnel,PDO::PARAM_INT);
		$req->execute();
		$donnee = $req->fetchAll(PDO::FETCH_OBJ);
		return $donnee;
	}
	
	public function getListeChambre($id_professionnel){
		$req = $this->pdo->prepare('SELECT * FROM chambre WHERE id_professionnel = :id');
		$req->bindValue(':id',$id_professionnel,PDO::PARAM_INT);
		$req->execute();
		$donnee = $req->fetchAll(PDO::FETCH_OBJ);
		return $donnee;
	}
	
	public function addOptionHotel($id_hotel){
		$req = $this->pdo->prepare('INSERT INTO option_hotel SET id_hotel = :id');
		$req->bindValue(':id',$id_hotel,PDO::PARAM_INT);
		$req->execute();
	}

    public function addOptionRestaurant($id_restaurant){
        $req = $this->pdo->prepare('INSERT INTO option_restaurant SET id_restaurant = :id');
        $req->bindValue(':id',$id_restaurant,PDO::PARAM_INT);
        $req->execute();
    }

    public function addOptionTraiteur($id_traiteur){
        $req = $this->pdo->prepare('INSERT INTO option_traiteur SET id_traiteur = :id');
        $req->bindValue(':id',$id_traiteur,PDO::PARAM_INT);
        $req->execute();
    }

	public function getOptionHotel($id_hotel){
		$req = $this->pdo->prepare('SELECT * FROM option_hotel WHERE id_hotel =:id');
		$req->bindValue(':id',$id_hotel,PDO::PARAM_INT);
		$req->execute();
		$donnee = $req->fetch(PDO::FETCH_OBJ);
		return $donnee;
	}

    public function getOptionRestaurant($id_restaurant){
        $req = $this->pdo->prepare('SELECT * FROM option_restaurant WHERE id_restaurant =:id');
        $req->bindValue(':id',$id_restaurant,PDO::PARAM_INT);
        $req->execute();
        $donnee = $req->fetch(PDO::FETCH_OBJ);
        return $donnee;
    }

    public function getOptionTraiteur($id_traiteur){
        $req = $this->pdo->prepare('SELECT * FROM option_traiteur WHERE id_traiteur =:id');
        $req->bindValue(':id',$id_traiteur,PDO::PARAM_INT);
        $req->execute();
        $donnee = $req->fetch(PDO::FETCH_OBJ);
        return $donnee;
    }

    public function updateOptionHotel(array $liste){
        $req = $this->pdo->prepare('UPDATE option_hotel SET tv =:tv, wifi =:wifi, internet =:internet, acces_handicapes
		 = :acces_handicapes, garage = :garage, parking = :parking, piscine_couverte =:piscine_couverte, climatisation =
		 :climatisation , seminaire=:seminaire, etape_affaire=:etape_affaire ,salle_gym =:salle_gym , lieu_calme = 
		 :lieu_calme, proche_transport = :proche_transport, animaux_acceptes= :animaux_acceptes WHERE id_hotel 
		 =:id_hotel');
        $donnee = @$req->execute($liste);
        if($donnee){
            return false;
        }
        return true;
    }

    public function updateOptionRestaurant(array $liste){
		$req = $this->pdo->prepare('UPDATE option_restaurant SET repas_amoureux = :repas_amoureux, repas_affaire =
		:repas_affaire, entre_amis = :entre_amis, ambiance_festive =:ambiance_festive, sortie_famille=:sortie_famille,
		anniversaire = :anniversaire, lieu_calme =:lieu_calme, rencontres=:rencontres, acces_handicapes= 
		:acces_handicapes, anglais_parle = :anglais_parle, wifi=:wifi,climatisation =:climatisation WHERE id_restaurant
		=:id_restaurant ');
		$donnee = @$req->execute($liste);
		 if($donnee){
			 return false;
		 } 
		 return true;
	}
	public function menuExist($id_utilisateur,$nom,$type,$prix){
		$req = $this->pdo->prepare('SELECT * FROM menu_restaurant WHERE id_professionnel = :id AND nom_menu = :nom AND
		type_menu = :type AND prix_menu = :prix ');
		$req->bindValue(':id',$id_utilisateur,PDO::PARAM_INT);
		$req->bindValue(':nom',$nom);
		$req->bindValue(':type',$type);
		$req->bindValue(':prix',$prix);
		$req->execute();
		$donnee = $req->fetch();
		return !empty($donnee);
	}
	
	public function addMenu($id_utilisateur,$nom,$type,$prix){
		$req = $this->pdo->prepare('INSERT INTO menu_restaurant SET id_professionnel = :id , nom_menu = :nom ,
		type_menu = :type , prix_menu = :prix ');
		$req->bindValue(':id',$id_utilisateur,PDO::PARAM_INT);
		$req->bindValue(':nom',$nom);
		$req->bindValue(':type',$type);
		$req->bindValue(':prix',$prix);
		$donnee = $req->execute();
		return !empty($donnee);
	}
	
	public function addChambre($id_professionnel,$type,$prix_min,$prix_max,$total){
		$req = $this->pdo->prepare('INSERT INTO chambre SET id_professionnel = :id , type_chambre = :type, prix_minimum 
		= :prix_min, prix_maximum = :prix_max , nombre_total = :total ');
		$req->bindValue(':id',$id_professionnel,PDO::PARAM_INT);
		$req->bindValue(':type',$type);
		$req->bindValue(':prix_min',$prix_min);
		$req->bindValue(':prix_max',$prix_max);
		$req->bindValue(':total',$total);
		$donnee = $req->execute();
		return !empty($donnee);
	}
	public function chambreExist($id_professionnel,$type,$prix_min,$prix_max,$total){
		$req = $this->pdo->prepare('SELECT * FROM chambre WHERE id_professionnel = :id AND type_chambre = :type AND
		 prix_minimum = :prix_min AND prix_maximum = :prix_max ');
		$req->bindValue(':id',$id_professionnel,PDO::PARAM_INT);
		$req->bindValue(':type',$type);
		$req->bindValue(':prix_min',$prix_min);
		$req->bindValue(':prix_max',$prix_max);
		$req->execute();
		$donnee = $req->fetch();
		return !empty($donnee);
	}
	public function supprimerMenu(array $listeId){
		for($i=0;$i<count($listeId);$i++){
			$req = $this->pdo->prepare('DELETE FROM menu_restaurant WHERE id_menu =:id');
			$req->bindValue(':id',$listeId[$i]);
			$req->execute();
		}
	}
	public function supprimerChambre(array $listeId){
		for($i=0;$i<count($listeId);$i++){
			$req = $this->pdo->prepare('DELETE FROM chambre WHERE id_chambre =:id');
			$req->bindValue(':id',$listeId[$i]);
			$req->execute();
		}
	}
	public function updateHoraire($lundi,$mardi,$mercredi,$jeudi,$vendredi,$samedi,$dimanche){
		$id = $_SESSION['id_utilisateur'];
		$req = $this->pdo->prepare('UPDATE horaire_restaurant SET lundi = :lundi, mardi = :mardi, mercredi = :mercredi
		, jeudi = :jeudi, vendredi = :vendredi, samedi = :samedi, dimanche = :dimanche WHERE id_restaurant = :id');
		$req->bindValue(':lundi',$lundi);
		$req->bindValue(':mardi',$mardi);
		$req->bindValue(':mercredi',$mercredi);
		$req->bindValue(':jeudi',$jeudi);
		$req->bindValue(':vendredi',$vendredi);
		$req->bindValue(':samedi',$samedi);
		$req->bindValue(':dimanche',$dimanche);
		$req->bindValue(':id',$id);
		$req->execute();
	}
	
	public function getListeImages(){
		$req = $this->pdo->prepare("SELECT * FROM banniere_image WHERE date_fin_pub >= :now ORDER BY
		priorite DESC LIMIT 0, 10 ");
		$now = date('Y-m-d')/*.' '.date('H:i:s');*/;
		$req->bindValue(':now',$now);
		$req->execute();
		$donnee = $req->fetchAll(PDO::FETCH_OBJ);
		return $donnee;
	}
}